﻿using Huirui.Cavan.Domain.Seedwork;
using System;
using System.Collections;
using System.Collections.Generic;
using Huirui.Cavan.Domain.MainBoundedContext.SystemModule;
using Huirui.Cavan.Core.Extension;

namespace Huirui.Cavan.Domain.MainBoundedContext.SalesModule
{
    #region SalesPrice

    /// <summary>
    /// SalesPrice object for NHibernate mapped table 'SalesPrice'.
    /// </summary>
    [Serializable]
    public class SalesPrice : Persistent<string>
    {
        #region Member Variables

        protected string _corporationCode;
        protected SalesIdentifier.PriceType _type;
        protected int _customerType;
        protected DateTime _startDate;
        protected DateTime? _endDate;
        protected string _remark;
        protected IList<Customer> _customers;
        protected IList<SalesPriceDetail> _salesPriceDetails;

        #endregion

        #region Constructors

        public SalesPrice() { }

        public SalesPrice(string id, string corporationCode, SalesIdentifier.PriceType type, int customerType, DateTime startDate, DateTime? endDate, string remark, DateTime createDate, DateTime modifyDate, int editUser)
        {
            this.Id = id;
            this._corporationCode = corporationCode;
            this._type = type;
            this._customerType = customerType;
            this._startDate = startDate;
            this._endDate = endDate;
            this._remark = remark;
            this._createDate = createDate;
            this._modifyDate = modifyDate;
            this._editUser = editUser;
        }

        #endregion

        #region Public Properties

        public virtual string CorporationCode
        {
            get { return _corporationCode; }
            set
            {
                if (value != null && value.Length > 20)
                    throw new ArgumentOutOfRangeException("Invalid value for CorporationCode", value, value.ToString());
                _corporationCode = value;
            }
        }

        public virtual SalesIdentifier.PriceType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public virtual int CustomerType
        {
            get { return _customerType; }
            set { _customerType = value; }
        }

        public virtual DateTime StartDate
        {
            get { return _startDate; }
            set
            {
                _startDate = value;
            }
        }

        public virtual DateTime? EndDate
        {
            get { return _endDate; }
            set { _endDate = value; }
        }

        public virtual string Remark
        {
            get { return _remark; }
            set { _remark = value; }
        }

        public virtual IList<Customer> Customers
        {
            get 
            {
                if (_customers.IsNull())
                {
                    _customers = new List<Customer>();
                }
                return _customers; 
            }
            set { _customers = value; }
        }

        public virtual IList<SalesPriceDetail> SalesPriceDetails
        {
            get
            {
                if (_salesPriceDetails.IsNull())
                {
                    _salesPriceDetails = new List<SalesPriceDetail>();
                }
                return _salesPriceDetails;
            }
            set { _salesPriceDetails = value; }
        }
        #endregion
    }
    #endregion
}